/**
 * 用户审核脚本
 * 
 * @author leichao
 */
orange.useraudit={
	// 计算top的值
	calculateTopValue: function(index) {
		var topValue = (index+1)*25 + 80;
		return topValue;
	},
	// 计算left的值
	calculateLeftValue: function() {
		var panelWidth = document.getElementById('org_userAuditDiv').style.width;
		var value = parseInt(panelWidth.substring(0,panelWidth.length-2));
		var leftValue = value*0.42+25;
		return leftValue;
	},
	finalCloseDiv: function() {
		$('#userAuditTypeWin').css({'display':'none'});
	},
	closeSuggest:function(){
		$('#userAuditNotPassWin').css({'display':'none'});
	},
	//字符串转化数组
	StrtoArry:function(str){
		var array=str.split(",");
		return array;
	},
	//渲染弹出框
	renderDiv:function(data,pid){	
		var length = data.length,div = document.getElementById(pid);
		for(var i=0;i<length;i++) {
			var span = document.createElement('span');
			span.innerText = data[i]+"\n";
			div.appendChild(span);
		}
	},
	queryParameter:function() {		//根据姓名用户名日期查找
		$.ajax({
			url:'useraudit/getUserauditService',
			type: "post",  
			data:{
				realname: $('#user_auditname').val(),
				username: $('#user_nickname').val(),
				auditstartdate: $('#user_auditstartDate').datebox('getValue'),
				auditenddate:$('#user_auditendDate').datebox('getValue'),
				page:1,
				rows:20
			},
			success:function(data){
				$('#org_userAuditGrid').datagrid('loadData',data.data);
			}
		});
	},
	disagree:function (selectId,selectIndex) {		//审核不通过
		$('#userAudit_auditsuggest').val('');
		$('#userAuditNotPassWin').css({'display':'block','left':'30px','top':orange.useraudit.calculateTopValue(selectIndex)+'px'});
	},
	agree: function (selectId,username,applyusertype){		//审核通过
		$.ajax({
			url:'useraudit/userauditPass',
			type: "post",  
			data:{
				aui:selectId,
				username:username,
				applyusertype:applyusertype
			},
			success:function(data){
				orange.useraudit.queryParameter();
			}
		});
		
	},
	saveOK:function() {		//审核不通过确定
		var row=$('#org_userAuditGrid').datagrid('getSelected');
		$.ajax({
			url:'useraudit/userauditNotPass',
			type: "post",  
			data:{
				aui:row.aui,
				username:row.username,
				auditsuggest:$('#userAudit_auditsuggest').val(),
			},
			success:function(data){
				$('#userAuditNotPassWin').css({'display':'none'});
				orange.useraudit.queryParameter();
			}
		});
	},
},
// 用户注册审核数据表格属性配置
$('#org_userAuditGrid').datagrid({
	url:'useraudit/getUserauditService',
	singleSelect : true,
	rownumbers : true,
	//点击单元格事件
	onClickCell:function(rowIndex,field,value){
		$('#audit_applyusertype_oldDiv').empty();
		$('#audit_applyusertype_applyDiv').empty();
		if(field=='oldusertype'||field=='applyusertype'){
			var rows = $('#org_userAuditGrid').datagrid('getRows');
			var data = rows[rowIndex];
			var oldArr = orange.useraudit.StrtoArry(data.oldusertype);
			var applyArr = orange.useraudit.StrtoArry(data.applyusertype);
			orange.useraudit.renderDiv(oldArr, 'audit_applyusertype_oldDiv');
			orange.useraudit.renderDiv(applyArr, 'audit_applyusertype_applyDiv');
			$('#userAuditTypeWin').css({'display':'block','left':orange.useraudit.calculateLeftValue()+'px','top':orange.useraudit.calculateTopValue(rowIndex)+'px','width':'30%'});
		}
	},
	columns : [[
        {field : 'agreeornot',title : '是否同意',width : '12%',
			formatter : function(value, row, index) {
				return '<a href="#" onclick="orange.useraudit.agree(\''+row.aui+'\',\''+row.username+'\',\''+row.applyusertype+'\')">同意</a>&nbsp&nbsp;'
				+'<a href="#" onclick="orange.useraudit.disagree(\''+row.aui+'\',\''+index+'\')">不同意</a>';
			}
		},
		{field : 'aui',hidden:true},
		{field : 'username',title : '用户名',width : '10%'},
		{field : 'realname',title : '姓名',width : '10%'},
		{field : 'applydate',title : '申请时间',width : '10%'},
		{field : 'oldusertype',title : '原用户类型',width : '20%'},
		{field : 'applyusertype',title : '申请用户类型',width : '20%'},
		{field : 'auditstatus',title : '审核状态',width : '10%'},
	]],
	pagination : true,
	striped : true,
	pageSize:20,
	pageList:[10,20,30,40,50]
});

/**
 * 当浏览器窗口发生变化时，调整弹出div的left值
 */
$(window).resize(function () {          //当浏览器大小变化时
	orange.useraudit.finalCloseDiv();
});

